﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Bling.DSL;
using Bling.WPF;
using Bling.Core;

namespace Bling.Tutorial {
  using Bling.Matrices;
  public class MatrixTest : Canvas {
    public MatrixTest() {
      CanvasBl Canvas = this;


      var RotateT = new ThumbBl(Canvas) {
        CanDrag = true, CenterPosition = new PointBl(100,100), ZIndex = 100, Background = Brushes.Red,
      };
      var Angle = new VecAngle2DBl(RotateT - Canvas.CenterSize);
      var Result = new ThumbBl(Canvas) {
        CenterPosition = Canvas.CenterSize + Angle.ToPoint * 100d, ZIndex = 10, Background = Brushes.Blue,
      };
      new LineBl(Canvas) { Start = Canvas.CenterSize, End = Result, ZIndex = 10, Stroke = { Thickness = 3 } };

      var AutumnA = new RectangleBl(Canvas) {
        Fill = new ImageBrushBl() { ImageSource = "Resources/Autumn.jpg".ImageFor(typeof(TransitionsTest)) },
        CenterPosition = Canvas.CenterSize,
        Width = 300d,
        Height = 400d, Opacity = 1,
      };
      var AutumnB = new RectangleBl(Canvas) {
        Fill = new ImageBrushBl() { ImageSource = "Resources/Autumn.jpg".ImageFor(typeof(TransitionsTest)) },
        CenterPosition = Canvas.CenterSize,
        Size = AutumnA.Size,
        Opacity = 0.5,
      };

      var useCenter = AutumnA.CenterSize;
      

      var matrixA = Angle.RotateAt(useCenter);
      var matrixB = Angle.RotateAt(0d);
      var matrixC = .25.PI().RotateAt(useCenter);
      matrixA = (new PointBl(.5d, 2d)).Scale(AutumnA.Size) * (matrixA);

      var Slider0 = new SliderBl(Canvas) {
        RightBottom = Canvas.Size, Width = Canvas.Width, Maximum = 1, Minimum = 0
      };
      PointBl testCenter = AutumnA.Size * Slider0.Value;

      var px = new ThumbBl(Canvas) {
        Background = Brushes.Red,
        CenterPosition = AutumnA.LeftTop + matrixA.Transform(testCenter),
        ZIndex = 10,
      };
      var py = new ThumbBl(Canvas) {
        Background = Brushes.Blue,
        CenterPosition = AutumnA.LeftTop + matrixB.Transform(testCenter),
        ZIndex = 10, Opacity = 0, // AutumnB.Opacity,
      };
      AutumnA.RenderTransform = new MatrixTransformBl() {
        Matrix = matrixA,
      };
      AutumnB.RenderTransform = new MatrixTransformBl() {
        Matrix = matrixB,
      };
    }
  }
}
